<template>
    <view class="container">
        <view class="div1 u-demo-block__content">
            <view class="div2">
                <view v-for="(s,index) in sort" :class="{'clicked':index==value2,'div2-1':true}" @click="changeSort(s,index)">
                    {{s.name}}
                </view>
            </view>
            <view class="div3">
                <view class="gridView">
                    <u-grid
                            :border="false"
                            col="4"
                    >
                        <u-grid-item
                                v-for="(listItem,listIndex) in sortSecondary"
                                :key="listIndex"
                        >
                            <img  :src="listItem.pictureUrl" style="width: 40px"/>
                            <text class="grid-text">{{listItem.name}}</text>
                        </u-grid-item>
                    </u-grid>
                    <u-toast ref="uToast" />
                </view>
            </view>
        </view>
        <!--底部导航杠-->
        <u-tabbar
                class="footbar"
                :value="value1"
                :fixed="false"
                :placeholder="false"
                :safeAreaInsetBottom="false"
        >
            <u-tabbar-item text="首页" icon="home"  @click="barToPage('/')" ></u-tabbar-item>
            <u-tabbar-item text="分类" icon="list" @click="barToPage('/pages/sjh/goodsSort')" ></u-tabbar-item>
            <u-tabbar-item text="购物车" icon="shopping-cart" @click="barToPage('/pages/sjh/shoppingCart')" ></u-tabbar-item>
            <u-tabbar-item text="我的" icon="account" @click="barToPage('/pages/sjh/own')" ></u-tabbar-item>
        </u-tabbar>
    </view>
</template>
<script>
    import Request from '../../utils/request'
    export default {
        data() {
            return{
                value2:0,
                value1:1,
                sort:[
                    {
                        id:'',
                        name:'',
                        list:[
                            {
                                id:'',
                                name:'',
                                pictureUrl:''
                            }
                        ]
                    }
                ],
                sortSecondary:[
                    {
                        id:'',
                        name:'',
                        pictureUrl:''
                    }
                ]
            }
        },
        mounted(){
            this.getSort()


        },
        methods:{
            /*底部导航跳转页面*/
            barToPage(url,val){
                console.log(url)
                uni.navigateTo({
                    url: url
                });
            },
            /*改变排序一级类型按钮*/
            async changeSort(s,index){
                console.log(index)
                this.value2=parseInt(index)
                this.sortSecondary=s.list
            },
            /*获取数据*/
            async getSort(){
                 await Request.request('management-mall/leyou.mall/mall-sort/getSort','','post').then(res=>{
                    console.info(res)
                    this.sort=res.data.list
                     this.changeSort(this.sort[0],0);
                }).catch(error=>{
                    console.error(error)
                })
            }

        }
    }
</script>

<style>
    .container {
        padding-bottom: 50px;
        font-size: 14px;
        line-height: 24px;
    }
    .footbar{
        margin: 0;
        width: 360px;
        position: fixed;
        bottom: 0;
    }
    .div1{
        height: 900px;
        position: relative;
    }
    .div2{
        height: 100%;
        position: absolute;
        left: 0;
        background: #B2B2B2;
        width: 30%;
    }
    .div2-1{
        text-align: center;
        padding: 15px 0;
    }
    .div3{
        height: 100%;
        position: absolute;
        right: 0;
        background: #e1f3d8;
        width: 70%;
    }
    .clicked{
        background: #e1f3d8;
    }
</style>
